package ossadaptor

import (
	"fmt"
)

// IOssHandler
type IOssHandler interface {
	Put(file string, objName string) (*UploadRet, error)
}

// UploadRet 上传结果struct
type UploadRet struct {
	Url string
}

func NewOssUploader(upType string, config map[string]string) (IOssHandler, error) {
	var oss IOssHandler
	var err error
	switch upType {
	case UploadByLocal:
		oss = NewLocalOss(config["bind_domain"], config["storage_path"])
	case UploadByQiniuOss:
		oss = NewQiniuOss(config["bind_domain"], config["access_key"], config["secret_key"])
	case UploadByAliyunOss:
		oss = NewAliyunOss(config["bind_domain"], config["access_key"], config["secret_key"])
	case UploadByMinioOss:
		oss, err = NewMinioOss(config["bind_domain"], &MinioOssOps{
			Endpoint:  config["bind_domain"],
			AccessKey: config["access_key"],
			SecretKey: config["secret_key"],
			Bucket:    config["bucket"],
			SubPath:   config["sub_path"],
		})
	}
	if err != nil {
		return oss, err
	}
	if oss == nil {
		return oss, fmt.Errorf("not support oss")
	}

	return oss, nil
}
